const fp = require('lodash/fp');
const {Maybe,Container} = require('./support');

//练习1
let maybe = Maybe.of([5,6,1]);
let ex1 = (arr)=> {
    let calcFn = fp.map(fp.add(1));
    return calcFn(arr);
}
let maybe1 = maybe.map(ex1)
console.log(maybe1);

//练习2
let xs = Container.of(['do','ray','me','fa','so','la','ti','do']);
let ex2 = (arr) => {
    let calcFn = fp.first;
    return calcFn(arr);
}
let xs1 = xs.map(ex2)
console.log(xs1);

//练习3
let safeProp = fp.curry(function(x,o){
    return Maybe.of(o[x]);
})
let user = {id:2,name:'Albert'};
let ex3 = (obj) => {
    let getName = safeProp('name');
    let getFirst = (functor) => {
        return functor.map(value => value.split('')[0])
    };
    let calcFn = fp.flowRight(getFirst,getName);
    return calcFn(obj);
}
let result3 = ex3(user);
console.log(result3);

//练习4
// let ex4 = function(n){
//     if(n){
//         return parseInt(n);
//     }
// }

let ex4 = function(n){
    return Maybe.of(n).map(parseInt);
}
console.log(ex4(null))
